package com.itany.config;

import com.itany.entity.ManagerUser;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Configuration
@ComponentScan
public class CheckLoginConfig implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 从session中获取员工信息
        ManagerUser user = (ManagerUser) request.getSession().getAttribute("managerUser");
        if (user == null) {
            request.setAttribute("loginMsg", "您尚未登录,请先登录!");
            request.getRequestDispatcher("/manager/showLogin").forward(request, response);
            return false;
        }
        return true;
    }
}
